//
//  HeadImageView.m
//  DZZTravel
//
//  Created by 赵国栋 on 16/7/14.
//  Copyright © 2016年 Eason. All rights reserved.
//



@interface HeadImageView ()

@property (nonatomic ,strong)UIButton *downBtn;


@property (nonatomic ,strong)NSMutableArray *cityNameArray;

@property (nonatomic ,strong)NSMutableArray *cityArray;


@end
@implementation HeadImageView

- (NSMutableArray *)cityArray{
    if (!_cityArray) {
        _cityArray = [NSMutableArray array];
        
    }
    return _cityArray;
}

//初始化方法
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatView];
        self.backgroundColor = [UIColor cyanColor];
        //打开图像用户交互
         self.userInteractionEnabled = YES;
        self.image = [UIImage imageNamed:@"head.png"];
     
    }
    return self;
}

- (NSMutableArray *)cityNameArray{
    
    if (!_cityNameArray) {
        _cityNameArray = [NSMutableArray array];
    }
    return _cityNameArray;
}
- (FDSlideBar *)slider{
    if (!_slider) {
        _slider = [[FDSlideBar alloc]init];

        _slider.itemColor = [UIColor redColor];
        _slider.itemSelectedColor = [UIColor cyanColor];
        
    }
    return _slider;
}


//创建btn
- (UIButton *)creatBtnWithcenter:(CGPoint)center action:(SEL)action frame:(CGRect)frame alpha:(float)alpha backImage:(NSString *)backImage{
    UIButton *btn = [[UIButton alloc]initWithFrame:frame];
    btn.center = center;
    btn.alpha = alpha;
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    if (backImage != nil) {
        UIImage *image = [UIImage imageNamed:backImage];
        UIImageView *vi = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 15, 15)];
        vi.image = image;
        [btn addSubview:vi];
    }
    return btn;
}

//下拉菜单
- (UIButton *)downBtn{
    if (!_downBtn) {
        _downBtn = [self creatBtnWithcenter:CGPointMake(KCollectViewCenterX*2+15, KCollectViewCenterY) action:@selector(downAction) frame:CGRectMake(0, 0, 60, 30) alpha:0.8 backImage:@"down.png"];
        _downBtn.backgroundColor = [UIColor clearColor];
        
    }
    return _downBtn;
}

//按钮点击方法
- (void)downAction{
     
    [self.delelgate upAndDown];
   
    
}


- (void)creatView{

    [self addSubview:self.downBtn];
    [self addSubview:self.slider];
    
    [RequestManager fectDataWithUrl:KcityNameUrl parameter:@{} method:@"GET" compelet:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        
        for (NSDictionary *dicc in dic[@"content"]) {
            
            cityName *city =[cityName new];
            [city setValuesForKeysWithDictionary:dicc];
            [self.cityArray addObject:city];
            [self.cityNameArray addObject:city.name];
            
        }
        
    } upDateUI:^{
        
        _slider.itemsTitle = self.cityNameArray;
        [_slider slideBarItemSelectedCallback:^(NSUInteger idx) {
          
            [self.delelgate jumpWithCityNmae:self.cityArray[idx]];
           
            
        }];
    
 
    }];
    
}




@end
